<?
	session_start();
	if ($_SESSION['ref']){
		$_GET['ref'] = $_SESSION['ref'];
	}
	if ($_GET['ref']){
		$_SESSION['ref'] = $_GET['ref'];
		setcookie("invref", $_GET['ref'], time()+86400);
		$_COOKIE['invref'] = $_GET['ref']; 
	}

	if ($loggedin){
		if ($logout) {
			$myname = "";
			$myrights = "";
			$myemail = "";
			$fid = "";
			$loggedin = 0;
			session_register("loggedin");
			session_register("myname");
			session_register("myuid");
			session_register("myrights");
			session_register("myemail");
			session_register("fid");
			$failed = 1;
		}
	}

	include("config.php");

	@mysql_connect($dbServer, $dbUser, $dbPass) or die("Couldn't connect to database server: " . mysql_error());
	@mysql_select_db($dbName) or die("Couldn't connect to database: " . mysql_error());

	function getPosts($forum){
		list($threads) = mysql_fetch_row( mysql_query("SELECT COUNT(*) FROM thread WHERE mb='$forum'") );
		list($posts) = mysql_fetch_row( mysql_query("SELECT COUNT(*) FROM posts,thread WHERE posts.threadid=thread.id AND thread.mb='$forum'") );	
		$theCount = $threads+$posts;
		return $theCount;
	}
	
	function errform($msg, $var = ''){ 
		global $posterr, $_POST; 
		$posterr = 1; 
		echo "<div style='color: #FF0000;'>$msg</div>";
		if ($var) $_POST[$var] = '';
	}

	function myround($amt,$dec="3"){
		ob_start();
		if($dec == 2){
			printf("%6.2f",$amt);
		}else{
			printf("%6.3f",$amt);
		}
		$amount = ob_get_contents();
		ob_end_clean(); 
		$amount = str_replace(" ","",$amount);
		return $amount;
	}

	class fptime{
		function fptime(){
			return 1;
		}

		function mytime($stamp="",$format="m/d/Y"){
			return date( $format,($stamp ? $stamp : time()) );
		}

		function stamp($mm,$dd,$yy,$hh=0,$min=0,$sec=0){
			return mktime($hh,$min,$sec,$mm,$dd,$yy);
		}

		function subhours($interval,$mm,$dd,$yy,$hh,$m,$s){
			return $this->stamp( $mm,$dd,$yy,($hh-$interval),$m,$s );
		}

		function addhours($interval,$mm,$dd,$yy,$hh,$m,$s){
			return $this->stamp( $mm,$dd,$yy,($hh+$interval),$m,$s );
		}

		function subdays($interval,$mm,$dd,$yy){
			return $this->stamp($mm,($dd-$interval),$yy);
		}

		function adddays($interval,$mm,$dd,$yy,$hh=0,$min=0,$sec=0){
			return $this->stamp($mm,($dd+$interval),$yy,$hh,$min,$sec);
		}

		function submonths($interval,$mm,$dd,$yy){
			return $this->stamp( ($mm-$interval),$dd,$yy );
		}

		function addmonths($interval,$mm,$dd,$yy){
			return $this->stamp( ($mm+$interval),$dd,$yy );
		}

		function subyears($interval,$mm,$dd,$yy){
			return $this->stamp( $mm,$dd,($yy-$interval) );
		}

		function addyears($interval,$mm,$dd,$yy){
			return $this->stamp( $mm,$dd,($yy+$interval) );
		}

		function DateDiff ($interval, $date1,$date2) {
			// get the number of seconds between the two dates
			$timedifference =  $date2 - $date1;
			switch ($interval) {
				case "w":
					$retval = $timedifference/604800;
					$retval = floor($retval);
					break;
				case "d":
					$retval = $timedifference/86400;
					$retval = floor($retval);
					break;
				case "h":
					$retval = $timedifference/3600;
					$retval = floor($retval);
					break;
				case "n":
					$retval = $timedifference/60;
					$retval = floor($retval);
					break;
				case "s":
					$retval  = floor($timedifference);
					break;
			}
			return $retval;
		}

		function dateNow($format="%Y%m%d"){
			return(strftime($format,time()));
		}

		function dateToday(){
			$ndate = time();
			return( $ndate );
		}

		function daysInMonth($month="",$year=""){
			if(empty($year)) {
				$year = $this->dateNow("%Y");
			}
			if(empty($month)) {
				$month = $this->dateNow("%m");
			}
			if($month == 2) {
				if($this->isLeapYear($year)) {
					return 29;
				} else {
					return 28;
				}
			} elseif($month == 4 or $month == 6 or $month == 9 or $month == 11) {
				return 30;
			} else {
				return 31;
			}
		}

		function isLeapYear($year=""){
			if(empty($year)) {
				$year = $this->dateNow("%Y");
			}
			if(strlen($year) != 4) {
				return false;
			}
			if(preg_match("/\D/",$year)) {
				return false;
			}
			return (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0);
		}
	}
?>